package com.example.androidexample.recyclerview;

import android.util.Log;
import android.view.View;
import android.widget.TextView;

import com.example.androidexample.R;
import com.example.basic.base.BaseRecyclerViewAdapter;

import java.util.ArrayList;
import java.util.List;

public class TestAdapter extends BaseRecyclerViewAdapter<DataBean> {

    
    private static final String TAG = "TestAdapter";
    
    private List<DataBean> mList = new ArrayList<>();
    private int layoutMode = 0;

    public void setLayoutMode(int layoutMode) {
        this.layoutMode = layoutMode;
    }

    public TestAdapter(List<DataBean> mList) {
        Log.d(TAG, "TestAdapter: ");
        this.mList.clear();
        this.mList.addAll(mList);
    }

    @Override
    public int getLayoutId(int viewType) {
        switch (layoutMode) {
            case 0:return R.layout.component_rv_vertical_item;
            case 1:return R.layout.component_rv_horizontal_item;
        }
        return R.layout.component_rv_vertical_item;
    }



    @Override
    protected DataBean getDataByPosition(int position) {
        return mList.get(position);
    }

    @Override
    protected int getTotalSize() {
        return mList.size();
    }

    @Override
    public void convert(VH holder, DataBean data, int position) {
        holder.<TextView>getView(R.id.tv_num).setText(position + 1 + "");
        holder.<TextView>getView(R.id.tv_content).setText(data.team);

        TextView view = holder.<TextView>getView(R.id.tv_area);
        view.setText(data.team);
        if (position == 0) {
            view.setVisibility(View.VISIBLE);
        } else {
            if (mList.get(position).area.equals(mList.get(position - 1).area)) {
                view.setVisibility(View.GONE);
            } else {
                view.setVisibility(View.VISIBLE);
            }
        }
    }
}
